package com.bdgls.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * Created by yibo on 2016-5-11.
 */
public class TextFileHelper {

    public static String getTextByFile(String filePath) {
        String result = "";
        BufferedReader br = null;

        StringBuffer sb = new StringBuffer();
        try {

            File file = new File(filePath);
            if (file.exists()) {

                br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

                char[] buff = new char[8];
                int read = br.read(buff, 0, buff.length);
                while (read >= 0) {
                    sb.append(buff, 0, read);
                    read = br.read(buff, 0, buff.length);
                }

                br.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        result = sb.toString();
        return result;
    }
}
